﻿/****************************************************************
 *				SkyFone DropDown Utils                          *
 *																*
 * File Name:  DropDown.js                                      *
 * Written by:  yangc											*
 * Important: to use this script don't							*
 *            remove these comments								*
 * Version 1.0 (MSIE 6.0 above,Firefox2.0,Netscape.)			*
 * Created Date: 2008-06-17										*
 ****************************************************************/
 
/** 
 * @fileoverview 
 * 该模块主要为页面模拟一个下拉选框择显示。

 *
 * @author  yangc (sheepchang@163.com)
 * @version 1.1
 */
Dipan.SanGuo.DropDown1 = 
{
	/** 
     * 构造函数

     */
	Initialize: function()
    {
		
    },
    
    /** 
     * 模板
     */
    Template:
    {   
        /** 
         * 提示选择模板
         */
        Outer:['<div class="hit_menu_all"><div class="hit_menu yellow2" id="${floatid}_count" style="cursor:pointer;">',
'<div class="hit_menu_left yellow4" id="${floatid}_item" name="${floatid}_item" onclick=\"Dipan.SanGuo.DropDown1.ShowItem(\'${floatid}\'); return false;\" onmouseout="Dipan.SanGuo.DropDown1._out();" onmouseover="Dipan.SanGuo.DropDown1._over();">${desc}</div>',

"<div class=\"hit_menu_right yellow1\" onclick=\"Dipan.SanGuo.DropDown1.ShowItem(\'${floatid}\');\" onmouseout=\"MM_swapImgRestore();Dipan.SanGuo.DropDown1._out();\" onmouseover=\"MM_swapImage('${floatid}_images','','${Dipan.SanGuo.Common.StaticsServer}/Statics/Images/float/xlk4.gif',1);Dipan.SanGuo.DropDown1._over();\"><img id=\"${floatid}_images\" border=\"0\" height=\"24\" name=\"${floatid}_images\" src=\"${Dipan.SanGuo.Common.StaticsServer}/Statics/Images/float/xlk3.gif\" width=\"19\" /></div>",
'</div></div>',
'<input type="hidden" id="${floatid}_hidden" name="${floatid}_hidden" />',
'<input type="hidden" id="${floatid}_jsondata" name="${floatid}_jsondata" />'],

        /** 
         * 下拉选择模板
         */
        Inner:['<div class="float_hit2" id="${floatid}_float" onmouseout="Dipan.SanGuo.DropDown1._out();" onmouseover="Dipan.SanGuo.DropDown1._over();">',
'<ul>',
'{for i in data}',
'<li class="property" onmouseover="this.style.backgroundColor=\'#3D3729\'" onmouseout="this.style.backgroundColor=\'\'" onclick="Dipan.SanGuo.DropDown1.SelectItem(\'${floatid}\',${i_index})" style="cursor:pointer;">${i.text}</li>',
'{/for}',
'</ul>',
'</div>']
    },
    
    timer:null,
    s_over:false, //是否在上面

    /** 
     * 生成提示选择
     * @param {JsonData} 显示的数据

     */
    Render: function(JsonData)
    {
        Dipan.SanGuo.DropDown1.JsonData = eval('('+JsonData+')');
        Dipan.SanGuo.Common.FixData(Dipan.SanGuo.DropDown1.Template.Outer, Dipan.SanGuo.DropDown1.JsonData.floatid, Dipan.SanGuo.DropDown1.JsonData, true);
        $(Dipan.SanGuo.DropDown1.JsonData.floatid + "_jsondata").value = JsonData;
        $(Dipan.SanGuo.DropDown1.JsonData.floatid + "_hidden").value = Dipan.SanGuo.DropDown1.JsonData.value;
    },
    
    /** 
     * 生成下拉框

     */
    ShowItem: function(floatid)
    {
        var obj = $("selcct_float");
        if (obj)
        {
            document.body.removeChild(obj);
            return;
        }
        this._fun();
        var citylist = $(floatid + "_float");
        if  (!citylist)
            Dipan.SanGuo.Common.FixData(Dipan.SanGuo.DropDown1.Template.Inner, "selcct_float", eval('('+$(floatid + "_jsondata").value+')'), true);
        citylist = $(floatid + "_float");
        var PosOuter = Dipan.SanGuo.Common.GetPosition($(floatid + "_count"));
        citylist.style.cssText = "position:absolute; z-index:2103757; display:none";
        if (!document.attachEvent)
        {
             citylist.style.top = (PosOuter[0] + 21) + "px";
             citylist.style.left = PosOuter[1]  + "px";
        }
        else
        {
             citylist.style.top = (PosOuter[0] + 23) + "px";
             citylist.style.left = PosOuter[1] + 2 + "px";
         }
         citylist.style.display = "block";
    },
    
    /** 
     * 选择选项
     * @param {floatid} 编号
     * @param {index} 选择的索引

     */
    SelectItem: function(floatid, index)
    {
        var JsonData = eval('('+$(floatid + "_jsondata").value+')');
        $(floatid + "_item").innerHTML = JsonData.data[index].text;
        $(floatid + "_hidden").value = JsonData.data[index].value;
        $(floatid + "_float").style.display = "none";
        
        if (JsonData.onchange)
        {
            eval(JsonData.onchange);
        }
    },
    _fun:function()
    {
        if(this.timer){clearTimeout(this.timer);this.timer=0;}
		this.timer= window.setTimeout('Dipan.SanGuo.DropDown1.SelectOut()',1000);
    },
    _over:function()//鼠标在上面

    {
        this.s_over=true;
    },
    _out:function()//鼠标移出
    {
        this.s_over=false;
    },
    /** 
     * 鼠标移出选择项

     */
    SelectOut: function()
    {
        if(this.s_over)
        {
            this._fun();
            return;
        }
        var obj = $("selcct_float");
        if (obj)document.body.removeChild(obj);
    }
}
